<?php
/**
 * Mailing List Report - allows you to view/print all users
 */

// get data for report
$order = 'id ASC';
$group = RM_UserGroups::REGULAR;
$filters = array();

$dao = new RM_Users;

// get the users details
$users = $dao->getAll(
    $group,
    $order,
    null,
    null,
    $filters,
    RM_Users::FILTER_TYPE_OR
)->toArray();

$total = count($users);

// transpose the titles to the textual values...
$titlesJSON="[{'id':'0','title':'Mr'},{'id':'1','title':'Mrs'},{'id':'2','title':'Miss'},{'id':'3','title':'Ms'}]";
$users = $dao->userTitles($users, str_replace(chr(39),chr(34),$titlesJSON));

?>

<style type="text/css">
<!--
body{
	font-family:Arial,Helvetica,sans-serif;
}
.tableheading{
	font-weight: bold;
}
.rm_report_text_body {
	margin-left: 20px;
	margin-right: 20px;
	font-size: 12px;
}
.row0 {
    background-color: #ffffff;
}

.row1 {
    background-color: #f0f0f0;
}

-->
</style>

<div class="rm_report_text_body">
    <b>Mailing List</b><br/>
    <hr>
    Total Users: <b><?php echo $total;?></b><br/><br/>
    <table width="100%" border="0" cellpadding="2" cellspacing="0">
        <tr>
            <th><b>Title</b></th>
            <th><b>First Name</b></th>
            <th><b>Last Name</b></th>
            <th><b>Email</b></th>
            <th><b>Phone Number</b></th>
            <th><b>Mobile Number</b></th>
            <th><b>Address</b></th>
            <th><b>City</b></th>
            <th><b>State</b></th>
            <th><b>Postcode</b></th>
            <th><b>Country</b></th>
        </tr>
    <?php
    $rowclass = 0;
    foreach($users as $user){
        ?>
        <tr class="row<?php echo $rowclass; ?>">
            <td><?php echo $user['title'];?></td>
            <td><?php echo $user['first_name'];?></td>
            <td><?php echo $user['last_name'];?></td>
            <td><?php echo $user['email'];?></td>
            <td><?php echo $user['telephone'];?></td>
            <td><?php echo $user['mobile'];?></td>
            <td><?php echo $user['address1']; if (!empty($user['address2'])) echo ", ".$user['address2'];?></td>
            <td><?php echo $user['city'];?></td>
            <td><?php echo $user['state'];?></td>
            <td><?php echo $user['postcode'];?></td>
            <td><?php echo $user['country'];?></td>
        </tr>
        <?php
        $rowclass = 1 - $rowclass;
    }
    ?>
    </table>
</div>